<?php
                                                                                                                                                                                                                                                                                                                                        
// TTTTTTTTTTTTTTTTTTTTTTT                  MMMMMMMM               MMMMMMMM                                CCCCCCCCCCCCMMMMMMMM               MMMMMMMM  SSSSSSSSSSSSSSS 
// T:::::::::::::::::::::T                  M:::::::M             M:::::::M                             CCC::::::::::::M:::::::M             M:::::::MSS:::::::::::::::S
// T:::::::::::::::::::::T                  M::::::::M           M::::::::M                           CC:::::::::::::::M::::::::M           M::::::::S:::::SSSSSS::::::S
// T:::::TT:::::::TT:::::T                  M:::::::::M         M:::::::::M                          C:::::CCCCCCCC::::M:::::::::M         M:::::::::S:::::S     SSSSSSS
// TTTTTT  T:::::T  TTTTTppppp   ppppppppp  M::::::::::M       M::::::::::M   eeeeeeeeeeee          C:::::C       CCCCCM::::::::::M       M::::::::::S:::::S            
//         T:::::T       p::::ppp:::::::::p M:::::::::::M     M:::::::::::M ee::::::::::::ee       C:::::C             M:::::::::::M     M:::::::::::S:::::S            
//         T:::::T       p:::::::::::::::::pM:::::::M::::M   M::::M:::::::Me::::::eeeee:::::ee     C:::::C             M:::::::M::::M   M::::M:::::::MS::::SSSS         
//         T:::::T       pp::::::ppppp::::::M::::::M M::::M M::::M M::::::e::::::e     e:::::e     C:::::C             M::::::M M::::M M::::M M::::::M SS::::::SSSSS    
//         T:::::T        p:::::p     p:::::M::::::M  M::::M::::M  M::::::e:::::::eeeee::::::e     C:::::C             M::::::M  M::::M::::M  M::::::M   SSS::::::::SS  
//         T:::::T        p:::::p     p:::::M::::::M   M:::::::M   M::::::e:::::::::::::::::e      C:::::C             M::::::M   M:::::::M   M::::::M      SSSSSS::::S 
//         T:::::T        p:::::p     p:::::M::::::M    M:::::M    M::::::e::::::eeeeeeeeeee       C:::::C             M::::::M    M:::::M    M::::::M           S:::::S
//         T:::::T        p:::::p    p::::::M::::::M     MMMMM     M::::::e:::::::e                 C:::::C       CCCCCM::::::M     MMMMM     M::::::M           S:::::S
//       TT:::::::TT      p:::::ppppp:::::::M::::::M               M::::::e::::::::e                 C:::::CCCCCCCC::::M::::::M               M::::::SSSSSSS     S:::::S
//       T:::::::::T      p::::::::::::::::pM::::::M               M::::::Me::::::::eeeeeeee          CC:::::::::::::::M::::::M               M::::::S::::::SSSSSS:::::S
//       T:::::::::T      p::::::::::::::pp M::::::M               M::::::M ee:::::::::::::e            CCC::::::::::::M::::::M               M::::::S:::::::::::::::SS 
//       TTTTTTTTTTT      p::::::pppppppp   MMMMMMMM               MMMMMMMM   eeeeeeeeeeeeee               CCCCCCCCCCCCMMMMMMMM               MMMMMMMMSSSSSSSSSSSSSSS   
//                        p:::::p                                                                                                                                       
//                        p:::::p                                                                                                                                       
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       ppppppppp                                                                                                                                      
                                                                                                                                                                     
//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/06/25
//      |_|                                         | TpMeCMS

namespace app\api\controller;
use app\api\controller\Tpmecms;
use think\Db;

/**
 * 邀请人公共接口🏚
 */
class Ltd extends Tpmecms
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['o'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];
    protected $user;

    public function _initialize()
    {
        parent::_initialize();
        $this->user = $this->GetLtdUserData($this->auth->id);//Db::name('user')->find($this->auth->id);

        
        // if($this->user['group_id']<2){
        //     $this->error('普通用户不能访问');
        // }

        // switch ($this->user['group_id']) {
        //     case '2':
        //         $this->user['teacher'] = $this->user['com'] = Db::name('teacher')->where('uid',$this->auth->id)->find();
        //         break;
        //     case '3':
        //         $this->user['ltder'] = $this->user['com'] = Db::name('ltder')->where('uid',$this->auth->id)->find();
        //         break;
            
        //     default:
        //         $this->user['teacher'] = $this->user['com'] = Db::name('teacher')->where('uid',$this->auth->id)->find();
        //         $this->user['ltder'] = $this->user['com'] = Db::name('ltder')->where('uid',$this->auth->id)->find();
        //         break;
        // }
       

       
        // group_id  1 普通用户 ，2 老师 3 公司
    }


    /**
     * 是否同意审核
     *
     * @return boolean
     */
    protected function is_agree()
    {
        if(!$this->user['ltder']['status_switch']){
            $this->error('暂未通过审核哦');
        }
    }

    /**
     * 是否是主管
     *
     * @return boolean
     */
    protected function is_zg(){
        $this->is_agree();
        if($this->user['ltder']['role_status']==1){
            return true;
        }else{
            $this->error('非公司主管');
        }
    }


    /**
     * 是否是员工
     *
     * @return boolean
     */
    protected function is_staff(){
        $this->is_agree();
        if($this->user['ltder']['role_status']=='2'){
            return true;
        }else{
            $this->error('非公司员工');
        }
    }

    /**
     * 是否是兼职人员
     *
     * @return boolean
     */
    protected function is_job(){
        $this->is_agree();
        if($this->user['ltder']['role_status']=='3'){
            return true;
        }else{
            $this->error('非公司员工');
        }
    }


    /**
     * 获取admin_id
     *
     * @return boolean
     */
    protected function get_admin_id(){
       
        if($this->user['ltder']['status_switch']!='1'){
            $this->error('未通过审核');
        }else{
            return $this->user['ltder']['admin_id'];
        }
    }

    /**
     * 申请公司
     * @param string $tel 电话
     * @param string $ltd_name 公司名称
     * @param string $name 法人姓名
     * @param string $images 营业执照
     * @return void
     */
    public function apply_ltd()
    {
        // $this->success('ok',$this->user);




        $data['uid'] = $this->auth->id;
        // $data['pid'] = $this->request->param('pid','');    
        $res = Db::name('ltd')->where($data)->find();
        if($res){
            $this->error('已提交过');
        }

        $data['name'] = $this->request->param('name','');
        $data['ltd_name'] = $this->request->param('ltd_name','');
     

        $data['tel'] = $this->request->param('tel');

        $data['images'] = $this->request->param('images');
        // $data['admin_id'] = $this->GetAdminIdByLtdId($data['ltd_id']);//

        // $data['role_status'] = '2';   //角色:1=主管,2=员工,3=兼职人员
        
        $data['time'] = time();
        $data['switch'] = 0;
        $res = Db::name('ltd')->insertGetId($data);
        if($res){
            $this->success('提交成功');
        }
        

        
    }










}
